<!DOCTYPE html>
<html lang="en" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common :: header('编辑菜单')"/>
    <style>
        .layui-form-label{
            width:80px;
        }
    </style>
</head>
<body>
<form action="" class="layui-form">
    <div class="">
        <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">上级</label>
                    <div class="layui-input-block">
                        <select name="parentId">
                            <option th:each="citem : ${parentList}" th:text="${citem.title}" th:value="${citem.id}" th:selected="${citem.id} eq ${item.parentId}">
                            </option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">菜单名称</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="title" name="title" placeholder="请输入菜单名称"
                               type="text" th:value="${item.title}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">图标</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="icon" name="icon" placeholder="请输入图标"
                               type="text" th:value="${item.icon}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="href" name="href" placeholder="请输入链接"
                               type="text" th:value="${item.href}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">类型</label>
                    <div class="layui-input-block">
                        <input checked name="type" title="菜单"  type="radio" value="1" th:checked="${item.type eq '1'}">
                        <input name="type" title="按钮"  type="radio" value="2" th:checked="${item.type eq '2'}">
                        <input name="type" title="目录"  type="radio" value="0" th:checked="${item.type eq '0'}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input checked name="status" title="隐藏"  type="radio" value="0" th:checked="${item.status eq '0'}" >
                        <input name="status" title="显示" type="radio"  value="1" th:checked="${item.status eq '0'}" >
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea class="layui-textarea" name="remark" placeholder="请输入备注" th:text="${item.remark}"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="listOrder" name="listOrder" placeholder="请输入排序"
                               type="text" th:value="${item.listOrder}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="hidden" name="id" th:value="${item.id}">
                        <button class="pear-btn pear-btn-primary" lay-submit lay-filter="formDemo">保存</button>
                    </div>
                </div>
        </div>
    </div>
</form>
</body>

<th:block th:include="common :: footer"/>
<script>
    layui.use(['form', 'jquery', 'layer'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;

        form.on('submit(formDemo)', function (data) {
            $.ajax({
                url: '/admin/menus/editPost',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("slide-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</html>